package com.rivulet.doj_backend.service.impl;

import com.rivulet.doj_backend.mapper.UserInformationMapper;
import com.rivulet.doj_backend.pojo.UserInformation;
import com.rivulet.doj_backend.service.UserInformationService;
import com.rivulet.doj_backend.tools.ResultFul;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserInformationServiceImpl implements UserInformationService {
    @Autowired
    UserInformationMapper userInformationMapper;

    @Override
    public ResultFul updateInformation(UserInformation userInformation) {
        ResultFul result =new ResultFul<UserInformation> (404,null);
        try{
            Integer id = userInformation.getId();
            UserInformation realUserInformation=userInformationMapper.getUserInformationById(id);
            if (realUserInformation != null){
                String nickname = userInformation.getNickname();
                String phone_number = userInformation.getPhone_number();
                Integer age = userInformation.getAge();
                Integer sex = userInformation.getSex();
                userInformationMapper.updateUserInformationById(nickname,age,sex,phone_number,id);
                result.setCode(100);
            }else{
                result.setCode(400);
            }
        }catch (Exception e){
            System.out.println("updateInformation_error:"+e);
        }
        return result;
    }

    @Override
    public ResultFul selectUserInformation(Object user_id) {
        ResultFul result =new ResultFul<UserInformation> (100,null);
        try {
            Integer id=(Integer) user_id;
            result.setData(userInformationMapper.getUserInformationById(id));
        }catch (Exception e){
            System.out.println(e);
        }finally {
            return result;
        }
    }
}
